package com.redission.redissiondemo.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.validation.annotation.Validated;

@Configuration
public class RedissionConfiguration {
    @Autowired
    Environment env ;

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson(){

        Config config = new Config();
        //单机模式  依次设置redis地址和密码
        config.useSingleServer().
                setAddress("redis://"+env.getProperty("spring.redis.host")+":"+env.getProperty("spring.redis.port"))
//                .setPassword(env.getProperty("spring.redis.password"));
        ;
        return Redisson.create(config);
    }
}
